package com.jwdf.uda.ui.adapter.viewholder;

import android.databinding.DataBindingUtil;
import android.view.View;
import android.widget.ImageView;
import com.jwdf.uda.R;
import com.jwdf.uda.bean.PbBean;
import com.jwdf.uda.databinding.ItemCommentMultiImageBinding;
import com.jwdf.uda.event.GuideDetailItemClickEvent;
import com.jwdf.uda.ui.activity.PhotoActivity;
import com.jwdf.uda.ui.activity.UserInfoActivity;
import com.jwdf.uda.ui.adapter.AbsViewHolder;
import com.jwdf.uda.ui.adapter.item.GuideDetailItem;
import com.jwdf.uda.utils.DateUtils;
import com.jwdf.uda.utils.EventBusUtil;
import com.jwdf.uda.view.GridImageLayout;
import java.util.ArrayList;
import java.util.List;

/**
 * 类说明：
 */
public class GuideCommentMultiImageViewHolder extends AbsViewHolder<GuideDetailItem> {
    private ItemCommentMultiImageBinding mItemBinding;
    public GuideCommentMultiImageViewHolder(View convertView) {
        super(convertView);
        mItemBinding = DataBindingUtil.bind(convertView);
        convertView.setOnClickListener(this);
        mItemBinding.topLayout.llHeadLayout.setOnClickListener(this);
    }

    @Override
    protected void onBindView(GuideDetailItem item) {
        PbBean.PbBaseComment comment = item.comment;
        if(comment == null) return;
        mItemBinding.setIsDesigner(comment.getUserInfo().getIsDesigner());
        mItemBinding.tvTime.setVisibility(View.VISIBLE);
        mItemBinding.tvTime.setText(DateUtils.getFriendlyTime(comment.getCreateTime()));
        GuideCommentTxtViewHolder.onBindCommonView(mItemBinding.topLayout, comment);

        final List<PbBean.PbImage> images = comment.getImageListList();
        final ArrayList<String> urls = new ArrayList<>();
        for (PbBean.PbImage image : images) {
            urls.add(image.getUrl());
        }
        mItemBinding.gridimageLayout.setImage(urls);
        mItemBinding.gridimageLayout.setOnImageItemClickListener(new GridImageLayout.OnImageItemClickListener() {
            @Override
            public void onImageClick(int index, ImageView imageView) {
                PhotoActivity.start(imageView.getContext(), urls, index);
            }
        });
    }
    @Override
    public void onClick(View v) {

        if(v.getId() == R.id.ll_head_layout){
            if(item.comment != null){
                UserInfoActivity.start(v.getContext(), item.comment.getUserInfo().getUserId(), item.comment.getUserInfo().getIsDesigner());
            }
            return;
        }
        EventBusUtil.post(new GuideDetailItemClickEvent(item));
    }
}
